package com.derbysoft.drc.billcheck

import java.io.{FileOutputStream, FileWriter}
import java.nio.charset.Charset

import org.apache.spark.{SparkConf, SparkContext}

/**
  * Created by xinliwang on 2017/6/3.
  */
object HotelResCodeCount {
  def main(args: Array[String]): Unit = {
    val conf = new SparkConf().setMaster("local").setAppName("HotelReservationCodeCount")
    val sc = new SparkContext(conf)


    val rdd = sc.textFile(args(0))
    val repeatHotelResvCode= rdd.map(line => {
      val split = line.split(",")
      (split(3),split(2))
    }).reduceByKey(_ + "," + _).filter(e =>e._2.contains(",")&&e._2.split(",").distinct.length==1).count()

    val outputStream = new FileWriter("/Users/xinliwang/workspace/billcheck/src/main/resources/result_hyatt.txt", true)
    try {

      val result = "******" + args(0) + "====>" + repeatHotelResvCode + "*********\n"
      outputStream.write(result)
      outputStream.flush()
      println(result)
    } finally {
      if (outputStream != null)
        outputStream.close()
    }


  }
}
